package com.bzy.blp.controller;

import com.bzy.blp.model.TPile;
import com.bzy.blp.model.TPileProject;
import com.bzy.blp.model.TPileRegion;
import com.bzy.blp.param.AddDrillingParam;
import com.bzy.blp.param.ShowPileDetailParam;
import com.bzy.blp.param.ShowPileParam;
import com.bzy.blp.service.BasePileManageService;
import com.bzy.common.bean.Result;
import com.bzy.common.exception.SpringValidException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/pile")
public class BasePileManageController {
	
	@Autowired
	private BasePileManageService basePileManageService;


	//创建、更新项目
	@RequestMapping(value = "/createProject",method= {RequestMethod.POST,RequestMethod.GET})
    public Result createProject(@Valid @RequestBody TPileProject tPileProject,BindingResult bindingResult) throws Exception {
        if(bindingResult.hasErrors()) {
        	throw new SpringValidException(bindingResult);
        }
		Result result = new Result();
        result.setData(basePileManageService.createAndUpdatePileProject(tPileProject));
        return result;
    }

    //展示项目
    @RequestMapping(value = "/showPileProject",method= {RequestMethod.POST,RequestMethod.GET})
    public Result showPileProject() throws Exception {
        Result result = new Result();
        result.setData(basePileManageService.showPileProject());
        return result;
    }

    //创建、更新区
    @RequestMapping(value = "/createRegion",method= {RequestMethod.POST,RequestMethod.GET})
    public Result createRegion(@Valid @RequestBody TPileRegion tPileRegion, BindingResult bindingResult) throws Exception {
        if(bindingResult.hasErrors()) {
            throw new SpringValidException(bindingResult);
        }
        Result result = new Result();
        result.setData(basePileManageService.createAndUpdateRegion(tPileRegion));
        return result;
    }

    //展示区
    @RequestMapping(value = "/showRegion",method= {RequestMethod.POST,RequestMethod.GET})
    public Result showRegion(Integer pileProjectId) throws Exception {
        Result result = new Result();
        result.setData(basePileManageService.showRegion(pileProjectId));
        return result;
    }

    //创建、更新桩
	@RequestMapping(value = "/createPile",method= {RequestMethod.POST,RequestMethod.GET})
    public Result createPile(@Valid @RequestBody TPile tPile, BindingResult bindingResult) throws Exception {
        if(bindingResult.hasErrors()) {
        	throw new SpringValidException(bindingResult);
        }
		Result result = new Result();
        result.setData(basePileManageService.createAndUpdatePile(tPile));
        return result;
    }

    //展示桩
	@RequestMapping(value = "/showPile",method= {RequestMethod.POST,RequestMethod.GET})
    public Result showPile(@RequestBody ShowPileParam showPileParam) throws Exception {
		Result result = new Result();
        result.setData(basePileManageService.showPile(showPileParam));
        return result;
    }

    //创建、更新钻孔
    @RequestMapping(value = "/createDrilling",method= {RequestMethod.POST,RequestMethod.GET})
    public Result createDrilling(@Valid @RequestBody AddDrillingParam addDrillingParam, BindingResult bindingResult) throws Exception {
        if(bindingResult.hasErrors()) {
            throw new SpringValidException(bindingResult);
        }
        Result result = new Result();
        result.setData(basePileManageService.createAndUpdateDrilling(addDrillingParam));
        return result;
    }

    //展示桩详情
	@RequestMapping(value = "/showPileDetail",method= {RequestMethod.POST,RequestMethod.GET})
    public Result showPileDetail(@Valid @RequestBody ShowPileDetailParam showPileDetailParam) throws Exception {
		Result result = new Result();
        result.setData(basePileManageService.showPileDetail(showPileDetailParam));
        return result;
    }

    //统计区域桩信息
    @RequestMapping(value = "/censusPiles",method= {RequestMethod.POST,RequestMethod.GET})
    public Result censusPiles(Integer regionId) throws Exception {
        Result result = new Result();
        result.setData(basePileManageService.censusPiles(regionId));
        return result;
    }

    //创建桩word
    @RequestMapping(value = "/createPileWord",method= {RequestMethod.POST,RequestMethod.GET})
    public Result createPileWord(@Valid @RequestBody List<ShowPileDetailParam> showPileDetailParams, BindingResult bindingResult) throws Exception {
        if(bindingResult.hasErrors()) {
            throw new SpringValidException(bindingResult);
        }
        Result result = new Result();
        result.setData(basePileManageService.createPileWord(showPileDetailParams));
        return result;
    }
	
}
